<link href="<?php echo site_url() ?>assets/css/nhatnv.css" media="all" rel="stylesheet" type="text/css" />
<div id="sidetabs_body_container">
    <div id="table_area" style="">
        <div id="action_bar" class="action_bar">
            
            <div id="list_header" class="list-device">
                <h1 id="page_title" class="db place_hide">Danh sách thiết bị</h1>
                <strong>Tổng số:</strong>
                <?php echo $sumDevice ?> devices
                <?php if ($this->session->userdata('level') != 3): ?>
                        <button onclick='window.location="<?php echo site_url() . 'add-device' ?>"' style="margin-left: 10px;padding: 4.4px;">Thêm mới</button>
            <?php endif; ?>
                
            </div>
            
            <div id="node_show_timespanner" class="place_hide dropdown-subtle-container" style="    float: left;width: 31%;">
                    <div class="l3search ">
                        <form method="get" id="form-search-device" style="float: left;width: 315px;margin-top: 6px;" action="<?php echo site_url() . 'device' ?>" style="float: left;">
                            <input type="hidden" name="time" value="<?php echo $time ?>"/>
                            <input type="hidden" name="id" id="_id_device" value=""/>
                            <div>
                                <span>
                                    <label>Từ khóa</label>
                                    <input type="search" style="width: 244px;padding: 5px;" name="smart_search" id="smart_search" value="<?php echo @$smart_search ?>" placeholder="Search clients..." >
                                    <button type="button" class="btn dropdown-toggle caret-select">
                                        <span class="caret"></span>
                                    </button>
                                </span>
                            </div>
                            <div class="div-search" id="div-search">
                                <span>
                                    <label for="network_group">Nhóm mạng</label>
                                    <?php echo $fview->selectOption($networkgroup, @$data->network_group ? @$data->network_group : $this->input->post('network_group'), '', 'network_group', 'network_group', 0, 'style="width: 100%;"'); ?>
                                </span>
                                <span id="provincehtml">
                                    <label>Tỉnh /thành phố</label>
                                    <select name="province_search">
                                        <option value="0">Chọn tỉnh thành</option>
                                    </select>
                                </span>
                                <span id="districthtml">
                                    <label>Quận / Huyện</label>
                                    <select name="district_search">
                                        <option value="0">Chọn quận huyện</option>
                                    </select>
                                </span>
                                <span id="placehtml">
                                    <label>Địa điểm</label>
                                    <select name="place_search">
                                        <option value="0">Chọn địa điểm</option>
                                    </select>
                                </span>

                                <span style="  text-align: right;">
                                    <label>&nbsp;</label>
                                    <input type="button" id="submit-search" value="Tìm kiếm" >
                                    <input type="button" id="cancel-serach" value="Đóng lại" >
                                </span>
                            </div>

                        </form>

                    </div>

                </div>
            
        </div>
        <div id="client_table" style="position:relative" class="flex-table add_col">
            
            <table class="filter compact fill">
                <thead>
                    <tr class="ft_head">
                        <th class="ft ftc undefined nodrag status ftsortable">
                <table class="lean" style="margin:0 auto">
                    <tbody>
                        <tr style="vertical-align:bottom">
                            <td style="padding:0 5px 0 0"></td>
                            <td class="ftlegend">Status</td>
                            <td style="padding:0 5px 0 0"></td>
                        </tr>
                    </tbody>
                </table>
                </th>
                <th class="ft ftl undefined nodrag description ftsortable">
                <table class="lean">
                    <tbody>
                        <tr style="vertical-align:bottom">
                            <td class="ftlegend">Tên thiết bị</td>
                            <td style="padding:0 5px"></td>
                        </tr>
                    </tbody>
                </table>
                </th>
                <th class="ft ftl  last_seen ftsortable">
                <table class="lean">
                    <tbody>
                        <tr style="vertical-align:bottom">
                            <td class="ftlegend">Admin device</td>
                            <td style="padding:0 5px"></td>
                        </tr>
                    </tbody>
                </table>
                </th>
                <th class="ft ftl  last_seen ftsortable">
                <table class="lean">
                    <tbody>
                        <tr style="vertical-align:bottom">
                            <td class="ftlegend">Nas ID</td>
                            <td style="padding:0 5px"></td>
                        </tr>
                    </tbody>
                </table>
                </th>
                <th class="ft ftl  usage ftsortable">
                <table class="lean">
                    <tbody>
                        <tr style="vertical-align:bottom">
                            <td class="ftlegend">Địa chỉ</td>
                        </tr>
                    </tbody>
                </table>
                </th>
                
                <th class="ft ftl  last_seen ftsortable">
                <table class="lean">
                    <tbody>
                        <tr style="vertical-align:bottom">
                            <td class="ftlegend">Last Online</td>
                            <td style="padding:0 5px"></td>
                        </tr>
                    </tbody>
                </table>
                </th>
                <th class="ft ftl  ip ftsortable">
                <table class="lean">
                    <tbody>
                        <tr style="vertical-align:bottom">
                            <td class="ftlegend">Tác vụ</td>
                            <td style="padding:0 5px"></td>
                        </tr>
                    </tbody>
                </table>
                </th>

                </tr>
                </thead>
                <tfoot>
                    <tr class="ft_foot">
                        <td class="ft_foot" colspan="11">
                            <div style="padding: 10px 10px;width: 100%"  id="pagination">
                                <?php echo $this->pagination->create_links(); ?>
                            </div>
                        </td>
                    </tr>
                </tfoot>
                <tbody>
                    <?php if ($data): ?>
                        <?php
                        $i = 0;
                        foreach ($data AS $el => $le):
                            ?>
                            <tr class="ftp<?php echo $i > 1 ? $i = 0 : $i ?>" data-idx="0" "="" id="item_k76d39b">
                                
                                <td class="ft undefined nodrag ftc">
                                    <?php echo $fview->ClassOnOff($le->time_update); ?> 
                                </td>
                                <td class="ft undefined nodrag">
                                    <a class="suppress_click" href="<?php echo site_url() . 'edit-device?id=' . md5($le->did) ?>"><?php echo $le->namedevice ?></a>
                                </td>
                                <td class="ft last_seen"><?php if(!in_array($le->admin, array(null, '', '0'))){foreach($le->admin AS $gv=>$vg){echo @$vg->username.', ';}}else{ echo 'No records';} ?></td>
                                <td class="ft usage"><?php echo $le->address.', '.$le->dname . ', ' . $le->pname ?></td>
                                <td class="ft last_seen"><?php echo $le->nasid ?></td>
                                <!-- <td class="ft os"><?php echo $fview->formatSizeUnits($le->bw); ?></td>
                                <td class="ft os"><?php echo $le->user; ?></td>  -->
                                <td class="ft os"><?php echo $le->lastonline; ?></td>
                                <td class="ft capabilities" style="padding-right: 0px">
                                    <a href="<?php echo site_url() . 'edit-device?id=' . md5($le->did) ?>" style="text-decoration: none;">
                                        Sửa
                                        <?php if ($this->session->userdata('level') != 3): ?>
                                        </a> 
                                        |
                                        <a style="cursor: pointer;text-decoration: none;" id="<?php echo md5($le->did); ?>" class="del_item">Xóa</a>
                                    <?php endif; ?>
                                </td>
                            </tr>
                            <?php
                            $i++;
                        endforeach;
                        ?>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>
<style>
    #pagination{
    }
    #pagination a{
        padding: 5px 10px;
        margin: 10px 2px;
        border: 1px solid #CCC;
        background: #6E6E6E;
        color: #FFF;
    }
    #pagination strong{
        padding: 5px 10px;
        margin: 10px 2px;
        border: 1px solid #CCC;
        background-color: #FFF;
    }
    .ft_add_col.btn-group {
        z-index: 0 !important;
    }
</style>
<script>
            $(document).ready(function ()
    {
    $('.caret-select').click(function () {
    $('#div-search').show();
    });
            $('#cancel-serach').click(function () {
    $('#div-search').hide();
    });
            $("#province").on('change', function ()
    {
    var id_province = $(this).val();
            $("#district_select").html('<input type="text" value="Plz, waitting..." class="form-control" name="">');
            $.ajax({
            type: 'get',
                    url: '<?php echo site_url('get-district'); ?>',
                    data: ({id: id_province}),
                    success: function (_data)
                    {
                    $("#district_select").html(_data);
                    }
            });
    });
            $('.del_item').click(function () {
    var r = confirm("Bạn có chắc chắn xóa thiết bị này không?");
            if (r == true) {
    window.location = '<?php echo site_url() . 'delete-device?id='; ?>' + this.id;
    } else {
    return false;
    }
    });
            $('#network_group').on('change', function ()
    {
    var ids = $(this).val();
            $('#provincehtml').html('<label>Tỉnh /thành phố</label><select name="province_search"><option value="0">Xin chờ...</option></select>');
            $('#districthtml').html('<label>Quận / Huyện</label><select name="district_search"><option value="0">Xin chờ...</option></select>');
            $('#placehtml').html('<label>Địa điểm</label><select name="place_search"><option value="0">Xin chờ...</option></select>');
            $('#devicehtml').html('<label>Thiết bị</label><select name="device_search" id="device_search"><option value="0">Xin chờ...</option></select>');
            $.ajax({
            type: 'post',
                    url: '<?php echo site_url() ?>get-province-device-member',
                    data: ({id: ids}),
                    success: function (html)
                    {
                    $('#provincehtml').html(html);
                            $('#districthtml').html('<label>Quận / Huyện</label><select name="district_search" id="district_search"><option value="0">Chọn quận huyện</option></select>');
                            $('#placehtml').html('<label>Địa điểm</label><select name="place_search" id="place_search"><option value="0">Chọn địa điểm</option></select>');
                            $('#devicehtml').html('<label>Thiết bị</label><select name="device_search" id="device_search"><option value="0">Chọn thiết bị</option></select>');
                    }
            });
    });
            $(document).on('change', '#province_search', function ()
    {
    var ids = $(this).val();
            var id_g = $('#network_group').val();
            $('#districthtml').html('<label>Quận / Huyện</label><select name="district_search"><option value="0">Xin chờ...</option></select>');
            $('#placehtml').html('<label>Địa điểm</label><select name="place_search"><option value="0">Xin chờ...</option></select>');
            $('#devicehtml').html('<label>Thiết bị</label><select name="device_search" id="device_search"><option value="0">Xin chờ...</option></select>');
            $.ajax({
            type: 'post',
                    url: '<?php echo site_url() ?>get-district-device-member',
                    data: ({id: ids, id_g: id_g}),
                    success: function (html)
                    {
                    $('#districthtml').html(html);
                            $('#placehtml').html('<label>Địa điểm</label><select name="place_search" id="place_search"><option value="0">Chọn địa điểm</option></select>');
                            $('#devicehtml').html('<label>Thiết bị</label><select name="device_search" id="device_search"><option value="0">Chọn thiết bị</option></select>');
                    }
            });
    });
            $(document).on('change', '#district_search', function ()
    {
    var ids = $(this).val();
            var id_g = $('#network_group').val();
            $('#placehtml').html('<label>Địa điểm</label><select name="place_search"><option value="0">Xin chờ...</option></select>');
            $('#devicehtml').html('<label>Thiết bị</label><select name="device_search" id="device_search"><option value="0">Xin chờ...</option></select>');
            $.ajax({
            type: 'post',
                    url: '<?php echo site_url() ?>get-place-device-member',
                    data: ({id: ids, id_g: id_g}),
                    success: function (html)
                    {
                    $('#placehtml').html(html);
                            $('#devicehtml').html('<label>Thiết bị</label><select name="device_search" id="device_search"><option value="0">Chọn thiết bị</option></select>');
                    }
            });
    });
       
        $('#submit-search').click(function ()
            {
                $('#form-search-device').submit();
            });
    });
</script>